﻿using Azure.Core;
using MediatR;
using W.Purchase.API.Application.Command.ClientCommand;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.ClientCommandHandler
{
    public class UnitAllDeleteCommandHandler : IRequestHandler<UnitAllDeleteCommand, int>
    {
        private IUnitRepository unit;
        public UnitAllDeleteCommandHandler(IUnitRepository unit)
        {
            this.unit = unit;

        }

        public async Task<int> Handle(UnitAllDeleteCommand request, CancellationToken cancellationToken)
        {
        
        var list = (await unit.GetAllAsaync()).Where(x => request.UnitId.Contains(x.UnitId)).ToList();
            list.ForEach(x =>
            {
                x.IsDelete = true;
                x.DeleteName = "张三";
                x.DeleteTime = DateTime.Now;
            });
            return await unit.UpdateRangeAsync(list);
        }
    }
}
